<?php
session_start();
include_once 'comm/config.php';
include_once 'comm/checkpostandget.php';

$uid=$_SESSION['dduserid']?$_SESSION['dduserid']:0;
$act=$_GET['act']?$_GET['act']:$_POST['act'];

if($act=='mall'){
	$id=$_GET['id']?(int)$_GET['id']:(int)$_POST['id'];
    $sql="select * from ".$BIAOTOU."mall where id=".$id;
	$query=mysql_query($sql);
	$mall=mysql_fetch_array($query);
	if($mall['lm']=='linktech'){
        $url="http://click.linktech.cn/?m=".$mall['merchant']."&a=".MALLWZBH."&l=99999&l_cd1=0&l_cd2=1&tu=".urlencode($mall['url'])."&u_id=0";
    }
    elseif($mall['lm']=='yiqifa'){
        $url=$mall['yilink'];
    }
	elseif($mall['lm']=='duomai'){
        $url="http://c.duomai.com/track.php?sid=".DUOMAIID.DUOMAIWBH."&aid=".$mall['duomaiid']."&euid=0&t=".urlencode($mall['url']);
    }
	elseif($mall['lm']=='chanet'){
        $url="http://count.chanet.com.cn/click.cgi?a=".CHANETWID."&d=".$mall['chanetid']."&u=0&e=";
    }
	
	$pic=$mall['logo'];
	$fan=$mall['fan'];
	$mallname=$mall['name'];
	$name=$mall['name'];
	$iframe_url=$mall['url'];
}
elseif($act=='cuxiao'){
	$id=$_GET['id']?(int)$_GET['id']:(int)$_POST['id'];
    $sql="select a.url,b.name,b.fan,b.logo,b.url as iframe_url from ".$BIAOTOU."activity as a,".$BIAOTOU."mall as b where a.id=".$id." and a.mallid=b.id";//获取活动信息
    $query=mysql_query($sql);
    $mall=mysql_fetch_array($query);
	$url=$mall['url'];
	if(strstr($url,'http://c.duomai.com/track.php')){
	    $url=str_replace(DUOMAIID,DUOMAIID.DUOMAIWBH,$url);
	}
	
	$pic=$mall['logo'];
	$fan=$mall['fan'];
	$mallname=$mall['name'];
	$name=$mall['name'];
	$iframe_url=$mall['iframe_url'];
}
elseif($act=='tg'){
    $id=$_GET['id']?(int)$_GET['id']:(int)$_POST['id'];
    $sql="select a.merchant,a.lm,a.yilink,a.duomaiid,a.name,a.fan,a.duomaiid,b.image,b.local,b.title from ".$BIAOTOU."mall as a,".$BIAOTOU."tuan_goods as b where b.id=".$id." and a.id=b.mall_id";//获取团购信息
    $query=mysql_query($sql);
    $mall=mysql_fetch_array($query);
	$url=$mall['url'];
	
	$pic=$mall['image'];
	$fan=$mall['fan'];
	$mallname=$mall['name'];
	$name=$mall['name'];
	$iframe_url=$mall['local'];
	
	if($mall['lm']=='linktech'){
        $url="http://click.linktech.cn/?m=".$mall['merchant']."&a=".MALLWZBH."&l=99999&l_cd1=0&l_cd2=1&tu=".urlencode($iframe_url)."&u_id=0";
    }
    elseif($mall['lm']=='yiqifa'){
        $yilink=$mall['yilink'];
	    $qu=strstr($yilink,'&t=');
	    $url=str_replace($qu,'&t='.urlencode($iframe_url),$yilink);
    }
	elseif($mall['lm']=='duomai'){
        $url="http://c.duomai.com/track.php?sid=".DUOMAIID.DUOMAIWBH."&aid=".$mall['duomaiid']."&euid=0&t=".urlencode($iframe_url);
    }
}

$input_arr=array('url'=>$url,'pic'=>$pic,'fan'=>$fan,'name'=>$name,'act'=>$act,'id'=>$id);
if($uid>0 && $url!=''){
	$url=add_uid_jump_url($url,$uid);
	if(!array_key_exists('p',$_POST)){
		$input_arr['p']=1;
	    echo postform('gotomall.php?act='.$act,$input_arr);
		exit;
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$name?> - <?=WEBTITLE?></title>
<link type="text/css" rel="stylesheet" href="css/alert.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="template/<?=MOBAN?>/js/base64.js"></script>
<script type="text/javascript" src="template/<?=MOBAN?>/js/function.js"></script>
<script type="text/javascript" src="js/fun.js"></script>
<script type="text/javascript" src="js/error.js"></script>
<style>
#desc{height:45px;font-size:14px;font-weight:bold}
#desc big{font-size:16px;color:#f00}

/* form avalidate */
form .field_notice { color:#9C9C9C; margin-left:5px; }
form .red { color:red; border:0px; background-color:#FFFFFF; }
form label.error { color:red; margin-left:5px; }
form input.error { border:red 1px dotted; }
form label.checking { padding-left:18px; background:transparent url(images/checking.gif) no-repeat; margin-left:5px; font-style:italic; color:#9C9C9C; display:none; }
form label.validate_right { padding-left:12px; background:transparent url(images/right.gif) no-repeat; margin-left:5px; font-style:italic; color:green; float:none; }
</style>
</head>
<body>
<?php
if(strstr($iframe_url,'amazon.cn') || strstr($iframe_url,'newegg.com') || strstr($iframe_url,'meituan.com') || strstr($iframe_url,'vipshop.com') || strstr($iframe_url,'51buy.com') || strstr($iframe_url,'fclub.cn')){
    $iframe_url='';
}
?>
<iframe frameborder="0" scrolling="no" src="<?=$iframe_url?>" marginwidth="0" marginheight="0" width="100%" class="ifrnameurl" id="flboxcontent"></iframe>
<div class="alert_fullbg"></div>
<div class="alert_bg" id="alert_fast_log_reg" style="display: block;">
	<div class="alert_box">
<div class="alert_top"><span>请登录领取该商城的返利</span><a class="alert_close" href="<?=$url?>"></a></div>
<div class="alert_content">
<div class="sort_info">
<div class="sort_pic"><?=html_img($pic,0,$row["name"])?></div>
<em></em>
<div class="sort_price">最高返：<b class="red"><?=$fan?></b>
</div>
<p><span class="blue">还不是<?=WEBNICK?>的会员？<a href="user/register.php" style="color:#F00; font-weight:bold" target="_blank">点击注册！</a></span><?php if($uid==0){?><a style="float:right" class="blue" href="<?php if($mall['lm']=='yiqifa'){echo urldecode($url);}else{echo $url;}?>">不要返利,先看看>></a><?php }else{?><a style="float:right" class="blue" href="<?php if($mall['lm']=='yiqifa'){echo urldecode($url);}else{echo $url;}?>">如果您的浏览器没有自动跳转，<b style="color:#F00">请点击这里</b></a><?php }?></p>
</div>
<?php if($uid>0){?>
<div class="login_reg" style="text-align:center">
<form name="loading" style=" width:100%;">
<div id="desc"><?=WEBTITLE?>正在带您去<big><?=$mallname?></big>（最高返<span style='color:#BD0000;'><?=$fan?></span>），请稍等</div>
<div id="tip" style="height:40px">
<input type=text name=chart size=46 style="font-family:Arial; font-weight:bolder; color:#fe6d01; background-color:#fff; padding:0px; border-style:none;">
<input name=percent size=47 style="color:#0066ff; text-align:center; border-width:medium; border-style:none;" type="hidden">
 </div>
 </form>
  </div>
<script>
function doClick(){
    var o=document.getElementById('goto');
    if(document.all){
        o.click();
    }else{
        window.location=o.href;
    }
}

var bar=0　 
var line="||"　 
var amount="||"　 
count();

function count(){　 
    bar=bar+2　 
    amount =amount + line　 
    document.loading.chart.value=amount　 
    document.loading.percent.value=bar+"%"　 
    if (bar<99){
		setTimeout("count()",10);
	}　 
    else{
        doClick();
    }　 
}
</script>
<?php }else{?>
<div class="login_reg">
<ul class="l_r_menu">
  <li><a href="javascript:;" class="l_log current">登录领取返利</a></li>
  <!--<li><a href="javascript:;" class="l_reg">注册领取返利</a></li>-->
</ul>
<div class="l_r_login" id="log">
  <div class="login">
  <form action="" method="post" onsubmit="return ajaxLogin(this)">
  
    <span class="fl">帐号：</span><input type="text" value="" class="login_name"  tabindex="1" name="ddusername" id="username1" />
    <div style="clear:both"></div>
    <span class="fl">密码：</span><input type="password" class="login_pwd"  tabindex="2" name="dduserpwd" id="password1"/>
    <div style="clear:both"></div>
    <font><input type="checkbox" class="checkbox" value="1" name="remember" id="remember" checked="checked"><label for="checkbox">记住我<span>（3个月免登陆）</span></label></font>
    <div style="clear:both"></div>
    <input type="hidden" name="submit" value="1" />
    <input type="hidden" name="from" value="ajax" />
    <div style="margin-top:10px;">
    <div style="float:left;margin-left:50px; _margin-left:20px"><input type="submit" class="button" value="登 录"  tabindex="3" /></div><div style="float:left;margin-left:20px;"><a href="user/getpassword.php" class="fo_psw" target="_blank">忘记密码?</a></div>
    </div>
    <div style="clear:both"></div>
  </form>
  </div>
  <div class="union_login"><p>友情提示：</p><div style="line-height:20px">商城返利已下<br/>单后以返回的<br/>订单为准！</div></div>
</div>
  <div class="login_reg" id="reg" style="display:none; padding-top:0px;">
  <div class="l_r_reg" id="fill">
  <form id="register_form" name="form" action="" method="post">
  <ul class="reg">
  <table border="0">
  
  <tr>
    <td><label for="username" class="fl">用户账号：</label></td>
    <td><input type="text" class="reg_name" id="username" tabindex="2" name="username" /></td>
    <td><label class="field_notice">用户名长度3-15位字母或数字</label><label id="checking_user" class="checking">检查中...</label></td>
  </tr>
  <tr>
    <td><label for="password" class="fl">登录密码：</label></td>
    <td><input type="password" class="reg_pwd" id="password" tabindex="2" name="password" /></td>
    <td><label class="field_notice">密码6～16位，区分大小写</label></td>
  </tr>
  <tr>
    <td><label for="password" class="fl">重复密码：</label></td>
    <td><input type="password" class="reg_pwd" id="password_confirm" tabindex="2" name="password_confirm" /></td>
    <td><label class="field_notice">密码6～16位，区分大小写</label></td>
  </tr>
  <tr>
    <td><label class="fl" for="email">电子邮箱：</label></td>
    <td><input type="text" value="" class="reg_email" id="email" tabindex="2" name="email" /></td>
    <td><label class="field_notice">请输入有效邮箱地址</label></td>
  </tr>
  <tr>
    <td><label for="qq" class="fl">填写QQ：</label></td>
    <td><input type="test" class="reg_pwd" id="qq" tabindex="2" name="qq" /></td>
    <td><label class="field_notice">填写您的QQ号</label></td>
  </tr>
  <tr>
    <td><label for="captcha" class="fl">写验证码：</label></td>
    <td><input name="captcha" type="text" id="captcha" size="6" tabindex="2" maxlength="4" style="width:136px;" class="ddinput"/>&nbsp;&nbsp;<img src="comm/showpic.php" border="0" align="absmiddle"/></td>
    <td><label class="field_notice">填写4位验证码</label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="hidden" name="submit" value="1" />
    <input type="hidden" name="from" value="ajax" />
    <input type="submit" class="button" value="注 册" tabindex="2" id="submits" /></td>
    <td>&nbsp;</td>
  </tr>
</table>
  </ul>
  </form>
  </div>
  </div>
  </div>
<?php }?>
</div>
</div>

</div>
<a id="goto" href="<?=$url?>">&nbsp;</a>
<script src="js/jquery.validate.js"></script>
<script type="text/javascript">
input=new Array();
input['url']='<?=$url?>';
input['pic']='<?=$pic?>';
input['fan']='<?=$_GET['fan']?>';
input['name']='<?=$name?>';
input['p']=1;
input['id']='<?=$id?>';
(function($) {
    var iheight;
    iheight = $(window).height();
    $('#flboxcontent').attr('height', iheight + 'px');
    $(window).resize(function() {
        iheight = $(window).height();
        $('#flboxcontent').attr('height', iheight + 'px');
    });
    var top = $(window).height() / 2 - $("#alert_fast_log_reg").height() / 2;
    var left = $(window).width() / 2 - $("#alert_fast_log_reg").width() / 2;
    $("#alert_fast_log_reg").css("left", left);
    $("#alert_fast_log_reg").css("top", top);
})(jQuery);

$(function(){
    $('.l_r_menu li a').click(function(){
	    $('.l_r_menu li a').removeClass('current');
		var classname=$(this).attr('class');
		if(classname=='l_log'){
		    $('#reg').hide();
			$('#log').show();
		}
		else if(classname=='l_reg'){
		    $('#log').hide();
			$('#reg').show();
		}
		$(this).addClass('current');
	});
});

function ajaxLogin(t){
	$.post('ajax.php?fun=checkLogin',$(t).serialize(),function(data){
		if(parseInt(data)>0){
			postForm('gotomall.php?act=<?=$act?>',input);
		}
		else{
		    alert('账号密码错误');
		}
	});
	return false;
}

$(function(){
    $('#register_form').validate({
        errorPlacement: function(error, element){
            var error_td = element.parent('td').next('td');
            error_td.find('.field_notice').hide();
            error_td.append(error);
        },
        success       : function(label){
            label.addClass('validate_right').text('OK!');
        },
        onkeyup: false,
        rules : {
            username : {
                required : true,
                byteRange: [3,15,'utf-8']
            },
            password : {
                required : true,
                minlength: 6
            },
            password_confirm : {
                required : true,
                equalTo  : '#password'
            },
            email : {
                required : true,
                email    : true
            },
            qq : {
                required : true,
                range:[1000,999999999999]
            },
			captcha : {
                required : true,
                rangelength:[4,4],
				digits:true
            }
        },
        messages : {
            username : {
                required : '您必须提供一个用户名',
                byteRange: '用户名必须在3-15个字符之间'
            },
            password  : {
                required : '您必须提供一个密码',
                minlength: '密码长度应在6-20个字符之间'
            },
            password_confirm : {
                required : '您必须再次确认您的密码',
                equalTo  : '两次输入的密码不一致'
            },
            email : {
                required : '您必须提供您的电子邮箱',
                email    : '这不是一个有效的电子邮箱'
            },
			qq : {
                required : '您必须提供您的QQ号码',
                range:'QQ号码位数错误'
            },
            captcha : {
                required : '请输入右侧图片中的字符',
				rangelength    : '位数错误',
				digits   : '这不是一个数字'
            }
        },
		submitHandler: function(form) {
            $.post('register.mod.php',$('#register_form').serialize(),function(data){
		        if(data=='ok'){
		            postForm('gotomall.php?act=<?=$act?>',input);
		        }
		        else{
		            alert(errorArr[data]);
		        }
	        });
        }
    });
});
</script>

</body>
</html>
